<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" lang="cn">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>修改合作成果信息</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <!-- Bootstrap 3.3.7 -->
    <!--link导入外部的css，js样式，如果导入的资源和本页面在同一个文件夹下，直接文件名即可-->
    <link rel="stylesheet" th:href="@{/asserts/bower_components/bootstrap/dist/css/bootstrap.min.css}">
    <!-- jQuery 3 -->
    <script th:src="@{/asserts/bower_components/jquery/dist/jquery.min.js}"></script>
    <!-- Bootstrap 3.3.7 -->
    <script th:src="@{/asserts/bower_components/bootstrap/dist/js/bootstrap.min.js}"></script>
    <!-- Font Awesome -->
    <link rel="stylesheet" th:href="@{/asserts/bower_components/font-awesome/css/font-awesome.min.css}">
    <!-- Ionicons -->
    <link rel="stylesheet" th:href="@{/asserts/bower_components/Ionicons/css/ionicons.min.css}">
    <!-- DataTables -->
    <link rel="stylesheet" th:href="@{/asserts/bower_components/datatables.net-bs/css/dataTables.bootstrap.min.css}">
    <!-- Theme style -->
    <link rel="stylesheet" th:href="@{/asserts/dist/css/AdminLTE.min.css}">

    <!--MyScript-->
    <script th:src="@{/asserts/Apolar_sh/lib/layer/2.4/layer.js}"></script>
    <!-- Google Font -->
    <link rel="stylesheet"
          href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,700,300italic,400italic,600italic">
</head>
<body>
<div class="wrapper">
    <!-- Content Wrapper. Contains page content -->
    <!-- Content Header (Page header) -->
    <section class="content-header">
        <h4>
            <i class="fa fa-edit"></i> 修改合作成果信息
        </h4>
    </section>

    <!-- Main content -->
    <section class="content">
        <div class="row">
            <div class="col-xs-12">
                <div class="box" style="width: 70%;margin: 0 auto;">
                    <div class="box-body">
                        <form id="modifyForm" class="form-horizontal">
                            <h4 style="text-align: center;font-weight: bold">修改成果信息</h4>
                            <br>
                            <div class="form-group">
                                <label class="col-sm-4 control-label"><span
                                        style="color: red;">*</span> 合作日期：</label>
                                <div class="col-sm-5">
                                    <input type="date" class="form-control" autocomplete="off" name="crDate"
                                           required th:value="${#dates.format(cr.crDate,'yyyy-MM-dd')}">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-4 control-label"><span
                                        style="color: red;">*</span> 成果类型：</label>
                                <div class="col-sm-5">
                                    <select id="crType" name="crType" class="form-control"
                                            required>
                                        <option disabled value="">--请选择成果类型--</option>
                                        <option th:value="内训" selected>内训</option>
                                    </select>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-4 control-label"><span
                                        style="color: red;">*</span> 成果主题：</label>
                                <div class="col-sm-5">
                                    <input id="crTopic" type="text" class="form-control" autocomplete="off"
                                           name="crTopic"
                                           placeholder="请输入成果主题" th:value="${cr.crTopic}"></div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-4 control-label"> 主题要求：</label>
                                <div class="col-sm-5">
                                    <input type="text" class="form-control" autocomplete="off" name="crTopicRequire"
                                           placeholder="请输入主题要求" th:value="${cr.crTopicRequire}">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-4 control-label"> 预期主题单价：</label>
                                <div class="col-sm-5">
                                    <input type="text" class="form-control" autocomplete="off"
                                           name="crTopicUnitprice" th:value="${cr.crTopicUnitprice}"
                                           placeholder="请输入预期主题单价"
                                           onchange="if(/\D/.test(value)){layer.msg('格式不对哦!请输入数字', {icon: 0, time: 1500});value='';}">
                                </div>
                                <p style="line-height: 35px;">元</p>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-4 control-label"> 预期主题总价：</label>
                                <div class="col-sm-5">
                                    <input type="text" class="form-control" autocomplete="off"
                                           name="crTopicTotalprice" th:value="${cr.crTopicTotalprice}"
                                           placeholder="请输入预期主题总价"
                                           onchange="if(/\D/.test(value)){layer.msg('格式不对哦!请输入数字', {icon: 0, time: 1500});value='';}">
                                </div>
                                <p style="line-height: 35px;">元</p>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-4 control-label"> 预期参与人数：</label>
                                <div class="col-sm-5">
                                    <input type="text" class="form-control" autocomplete="off" name="crPersonNum"
                                           placeholder="请输入预期参与人数" th:value="${cr.crPersonNum}"
                                           onchange="if(/\D/.test(value)){layer.msg('格式不对哦!请输入数字', {icon: 0, time: 1500});value='';}">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-4 control-label"><span
                                        style="color: red;">*</span> 授课讲师：</label>
                                <div class="col-sm-5">
                                    <select name="crCourseTid" id="crCourseTid" class="form-control">
                                        <option disabled value="">--请选择授课讲师--</option>
                                        <option th:each="teacher:${teacherList}"
                                                th:value="${teacher.tId}"
                                                th:selected="${cr.crCourseTid+''==teacher.tId+''}">[[${teacher.tName }]]
                                        </option>
                                    </select>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-4 control-label"><span
                                        style="color: red;">*</span> 销售专员：</label>
                                <div class="col-sm-5">
                                    <select name="crSalesUid" id="crSalesUid" class="form-control">
                                        <option disabled value="">--请选择销售专员--</option>
                                        <option th:each="sales:${salesList}"
                                                th:value="${sales.uid}"
                                                th:selected="${cr.crSalesUid+''==sales.uid+''}">[[${sales.personname }]]
                                        </option>
                                    </select>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-4 control-label"> 备注：</label>
                                <div class="col-sm-5">
                                    <textarea class="form-control" rows="3" cols="60" name="crRemark"
                                              placeholder="请输入备注信息">[[${cr.crRemark }]]</textarea>
                                </div>
                            </div>
                            <br>
                            <div class="form-group">
                                <div style="text-align: center;">
                                    <a th:if="${(comId == ''||comId==null)&& (ccrcTopic == ''||ccrcTopic ==null) && (ccrcDate ==''||ccrcDate==null)&& (ccrcSales ==''||ccrcSales==null)&& (ccrcCourseTeacher ==''||ccrcCourseTeacher==null)}"
                                       class="btn btn-danger"
                                       th:href="@{crShow(currentPage=${currentPage},pageSize=${pageSize})}">
                                        <i class="fa fa-backward"></i>&nbsp;返&nbsp;回
                                    </a>&nbsp;
                                    <a th:if="${!((comId == ''||comId==null)&& (ccrcTopic == ''||ccrcTopic ==null) && (ccrcDate ==''||ccrcDate==null)&& (ccrcSales ==''||ccrcSales==null)&& (ccrcCourseTeacher ==''||ccrcCourseTeacher==null))}"
                                       class="btn btn-danger"
                                       th:href="@{crSearchShow(currentPage=${currentPage},pageSize=${pageSize},comId=${comId},ccrcTopic = ${ccrcTopic},ccrcDate=${ccrcDate},ccrcCourseTeacher=${ccrcCourseTeacher},ccrcSales=${ccrcSales})}">
                                        <i class="fa fa-backward"></i>&nbsp;返&nbsp;回
                                    </a>&nbsp;
                                    <button type="reset" class="btn btn-info" id="resetBtn"
                                            onclick="layer.msg('重置成功！', {icon: 1, time: 1500});">
                                        <i class="fa fa-repeat"></i>&nbsp;重&nbsp;置
                                    </button>&nbsp;
                                    <button type="button" class="btn btn-success"
                                            th:onclick="modifySubmit([[${cr.crId}]])">
                                        &nbsp;&nbsp;&nbsp;<i class="fa fa-check-square"></i>&nbsp;&nbsp;&nbsp;提&nbsp;&nbsp;&nbsp;交&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                    </button>
                                </div>
                            </div>
                            <input id="currentPage" th:value="${currentPage}" hidden>
                            <input id="pageSize" th:value="${pageSize}" hidden>
                            <input id="comId" th:value="${comId}" hidden>
                            <input id="ccrcDate" th:value="${ccrcDate}" hidden>
                            <input id="ccrcTopic" th:value="${ccrcTopic}" hidden>
                            <input id="ccrcSales" th:value="${ccrcSales}" hidden>
                            <input id="ccrcCourseTeacher" th:value="${ccrcCourseTeacher}" hidden>
                        </form>

                    </div>
                    <!-- /.box-body -->
                </div>
                <!-- /.box -->
            </div>
            <!-- /.col -->
        </div>
        <!-- /.row -->
    </section>
    <!-- /.content -->
</div>

<!-- ./wrapper -->


<!-- DataTables -->
<script th:src="@{/asserts/bower_components/datatables.net/js/jquery.dataTables.min.js}"></script>
<script th:src="@{/asserts/bower_components/datatables.net-bs/js/dataTables.bootstrap.min.js}"></script>
<!-- SlimScroll -->
<script th:src="@{/asserts/bower_components/jquery-slimscroll/jquery.slimscroll.min.js}"></script>
<!-- FastClick -->
<script th:src="@{/asserts/bower_components/fastclick/lib/fastclick.js}"></script>
<!-- AdminLTE App -->
<script th:src="@{/asserts/dist/js/adminlte.min.js}"></script>
<!-- AdminLTE for demo purposes -->
<script th:src="@{/asserts/dist/js/demo.js}"></script>
<!-- page script -->
<script>

    $("form").submit(
        function () {
            var crTopic = $("#crTopic").val();
            var crCourseTid = $("#crCourseTid").val();
            var crSalesUid = $("#crSalesUid").val();
            if ((crTopic == null || crTopic === "")) {
                layer.msg('亲，成果主题不能为空哦!', {
                    icon: 0,
                    time: 1500
                });
                return false;
            } else if ((crCourseTid == null || crCourseTid === "")) {
                layer.msg('亲，请选择授课讲师哦!', {
                    icon: 0,
                    time: 1500
                });
                return false;
            } else if ((crSalesUid == null || crSalesUid === "")) {
                layer.msg('亲，请选择销售专员哦!', {
                    icon: 0,
                    time: 1500
                });
                return false;
            }
            return true;
        }
    );
    th:action = "@{/cr/crModify(crId=${cr.crId},currentPage=${currentPage},pageSize=${pageSize})}"

    function modifySubmit(crId) {
        var crTopic = $("#crTopic").val();
        var crCourseTid = $("#crCourseTid").val();
        var crSalesUid = $("#crSalesUid").val();
        if ((crTopic == null || crTopic === "")) {
            layer.msg('亲，成果主题不能为空哦!', {
                icon: 0,
                time: 1500
            });
        } else if ((crCourseTid == null || crCourseTid === "")) {
            layer.msg('亲，请选择授课讲师哦!', {
                icon: 0,
                time: 1500
            });
        } else if ((crSalesUid == null || crSalesUid === "")) {
            layer.msg('亲，请选择销售专员哦!', {
                icon: 0,
                time: 1500
            });
        } else {
            layer.confirm("确认提交吗？",
                {
                    btn: ['确定', '取消']
                },
                function () {
                    var pageSize = $("#pageSize").val();
                    var currentPage = $("#currentPage").val();
                    var comId = $("#comId").val();
                    var ccrcTopic = $("#ccrcTopic").val();
                    var ccrcDate = $("#ccrcDate").val();
                    var ccrcSales = $("#ccrcSales").val();
                    var ccrcCourseTeacher = $("#ccrcCourseTeacher").val();
                    $.ajax({
                        type: 'POST',
                        url: './crModify?crId=' + crId,
                        data: $("#modifyForm").serialize(),
                        success: function (data) {
                            if (data.id === 0) {
                                layer.msg(data.data, {
                                    icon: 1,
                                    time: 500
                                });
                                setTimeout(function () {
                                    if (comId === "" && ccrcTopic === "" && ccrcDate === "" && ccrcSales === "" && ccrcCourseTeacher === "") {
                                        location.replace('[[${#httpServletRequest.getContextPath()}]]' + '/cr/crShow?currentPage=' + currentPage + '&pageSize=' + pageSize);
                                    } else {
                                        location.replace('[[${#httpServletRequest.getContextPath()}]]' + '/cr/crSearchShow?currentPage=' + currentPage + '&pageSize=' + pageSize + '&comId=' + comId + '&ccrcTopic=' + ccrcTopic + '&ccrcDate=' + ccrcDate + '&ccrcCourseTeacher=' + ccrcCourseTeacher + '&ccrcSales=' + ccrcSales);
                                    }
                                }, 500);
                            } else {
                                layer.msg(data.data, {
                                    icon: 0,
                                    time: 2000
                                });
                            }
                        },
                        error: function (data) {
                            console.log(data.msg);
                        }
                    });
                },
                function () {
                    layer.msg("已取消！", {
                        icon: 0,
                        time: 500
                    });
                    return false;
                }
            );
        }
    }
</script>
</body>
</html>